<script setup lang="ts">
import { ref, computed, watch, onMounted, onBeforeUnmount } from "vue";
import { ElMessage, ElMessageBox } from "element-plus";

import type { Conversation } from "../../../types/conversation";
import type { Message } from "../../../types/message";
import {
  getConversationList,
  getConversationDetail,
  removeConversation,
  type ConversationDTO,
  type MessageDTO,
} from "../../../api/history";

const conversations = ref<Conversation[]>([]);
const total = ref(0);
const loadedCount = ref(0);
const isLoading = ref(false);
const isLoadingMore = ref(false);
const errorMessage = ref("");
const detailLoading = ref(false);
const detailError = ref("");

const searchKeyword = ref("");
const startDate = ref("");
const endDate = ref("");
const sourceFilter = ref<"" | "internal" | "external">("");
const showDetail = ref(false);
const activeConversation = ref<Conversation | null>(null);

const pageSize = 10;
let fetchTimer: ReturnType<typeof setTimeout> | null = null;

const activeMessages = computed<Message[]>(() => {
  return activeConversation.value?.messages ?? [];
});

const normalizeDateTime = (value?: string | null): string => {
  if (!value) {
    return "--";
  }

  const normalized = value.includes("T") ? value : value.replace(/-/g, "/");
  const date = new Date(normalized);

  if (Number.isNaN(date.getTime())) {
    return value;
  }

  const pad = (num: number) => num.toString().padStart(2, "0");
  return `${date.getFullYear()}-${pad(date.getMonth() + 1)}-${pad(
    date.getDate()
  )} ${pad(date.getHours())}:${pad(date.getMinutes())}:${pad(
    date.getSeconds()
  )}`;
};

const transformMessage = (message?: MessageDTO): Message => ({
  id: message?.id ?? 0,
  content: message?.content ?? "",
  role: message?.role === "user" ? "user" : "assistant",
  status: message?.status ?? "normal",
});

const transformConversation = (
  conversation: ConversationDTO,
  fallback?: Conversation
): Conversation => {
  const messages = (conversation.messages ?? []).map(transformMessage);

  return {
    id: String(
      conversation.id ?? fallback?.id ?? conversation.session_id ?? ""
    ),
    sessionId: conversation.session_id ?? fallback?.sessionId,
    title: conversation.title ?? fallback?.title ?? "未命名对话",
    messages: messages.length ? messages : fallback?.messages ?? [],
    createdAt: normalizeDateTime(
      conversation.created_at ?? fallback?.createdAt
    ),
    updatedAt: normalizeDateTime(
      conversation.updated_at ?? fallback?.updatedAt
    ),
    source: conversation.source ?? fallback?.source,
  };
};

const buildQueryParams = (skip: number) => {
  const keyword = searchKeyword.value.trim();
  return {
    skip,
    limit: pageSize,
    keyword: keyword || undefined,
    start_date: startDate.value || undefined,
    end_date: endDate.value || undefined,
    source: sourceFilter.value || undefined,
  };
};

const fetchConversations = async ({ reset = false } = {}) => {
  if (reset) {
    errorMessage.value = "";
    loadedCount.value = 0;
    total.value = 0;
  }

  if (isLoading.value || isLoadingMore.value) {
    if (!reset) {
      return;
    }
  }

  try {
    if (reset) {
      isLoading.value = true;
    } else {
      isLoadingMore.value = true;
    }

    const skip = reset ? 0 : loadedCount.value;
    const params = buildQueryParams(skip);
    const response = await getConversationList(params);
    total.value = response.total ?? 0;

    const items = (response.conversations ?? []).map((conversation) =>
      transformConversation(conversation)
    );

    if (reset) {
      conversations.value = items;
      loadedCount.value = items.length;
    } else if (items.length) {
      conversations.value = [...conversations.value, ...items];
      loadedCount.value += items.length;
    }
  } catch (error: unknown) {
    const message =
      typeof error === "string"
        ? error
        : error instanceof Error
        ? error.message
        : "加载对话记录失败";

    if (reset) {
      errorMessage.value = message;
      conversations.value = [];
      loadedCount.value = 0;
      total.value = 0;
    }

    ElMessage.error(message);
  } finally {
    if (reset) {
      isLoading.value = false;
    } else {
      isLoadingMore.value = false;
    }
  }
};

const scheduleFetch = () => {
  if (fetchTimer) {
    clearTimeout(fetchTimer);
  }

  fetchTimer = setTimeout(() => {
    fetchConversations({ reset: true });
  }, 400);
};

watch([searchKeyword, startDate, endDate, sourceFilter], scheduleFetch);

onMounted(() => {
  fetchConversations({ reset: true });
});

onBeforeUnmount(() => {
  if (fetchTimer) {
    clearTimeout(fetchTimer);
  }
});

const openDetail = async (conversation: Conversation) => {
  activeConversation.value = conversation;
  detailError.value = "";
  showDetail.value = true;
  detailLoading.value = true;

  try {
    const detail = await getConversationDetail(conversation.id);
    const transformed = transformConversation(detail, conversation);
    activeConversation.value = transformed;

    const index = conversations.value.findIndex(
      (item) => item.id === transformed.id
    );
    if (index !== -1) {
      conversations.value.splice(index, 1, transformed);
    }
  } catch (error: unknown) {
    const message =
      typeof error === "string"
        ? error
        : error instanceof Error
        ? error.message
        : "加载详情失败";
    detailError.value = message;
    ElMessage.error(message);
  } finally {
    detailLoading.value = false;
  }
};

const closeDetail = () => {
  showDetail.value = false;
  activeConversation.value = null;
  detailError.value = "";
};

const deleteConversation = async (conversationId: string) => {
  ElMessageBox.confirm("确定要删除这条对话记录吗？", "提示", {
    confirmButtonText: "确定",
    cancelButtonText: "取消",
    type: "warning",
  })
    .then(async () => {
      try {
        await removeConversation(conversationId);
        ElMessage.success("对话记录已删除");

        if (activeConversation.value?.id === conversationId) {
          closeDetail();
        }

        await fetchConversations({ reset: true });
      } catch (error: unknown) {
        const message =
          typeof error === "string"
            ? error
            : error instanceof Error
            ? error.message
            : "删除对话记录失败";
        ElMessage.error(message);
      }
    })
    .catch(() => {
      // 用户取消操作
    });
};

const resetFilters = () => {
  searchKeyword.value = "";
  startDate.value = "";
  endDate.value = "";
  sourceFilter.value = "";
};

const getSourceLabel = (source?: string) => {
  if (source === "internal") return "内部系统";
  if (source === "external") return "外部系统";
  return "未知";
};
</script>

<template>
  <div class="history-container">
    <div class="history-header">
      <div>
        <h1>对话历史管理</h1>
      </div>
      <div class="header-actions">
        <div class="search-box">
          <input
            v-model="searchKeyword"
            type="text"
            placeholder="搜索对话标题、编号或消息内容"
          />
          <span class="search-icon" aria-hidden="true"></span>
        </div>
        <div class="filter-group">
          <label class="filter-field">
            <span>开始日期</span>
            <input v-model="startDate" type="date" />
          </label>
          <label class="filter-field">
            <span>结束日期</span>
            <input v-model="endDate" type="date" />
          </label>
          <label class="filter-field">
            <span>来源</span>
            <select v-model="sourceFilter">
              <option value="">全部</option>
              <option value="internal">内部系统</option>
              <option value="external">外部系统</option>
            </select>
          </label>
          <button class="reset-btn" @click="resetFilters">重置筛选</button>
        </div>
      </div>
    </div>

    <div class="history-content">
      <div class="table-container">
        <table class="history-table">
          <thead>
            <tr>
              <th>对话开头</th>
              <th>来源</th>
              <th>消息数量</th>
              <th>创建时间</th>
              <th>最近更新时间</th>
              <th class="actions-col">操作</th>
            </tr>
          </thead>
          <tbody>
            <tr v-for="conversation in conversations" :key="conversation.id">
              <td>
                <div class="title">{{ conversation.title }}</div>
              </td>
              <td>
                <span class="source-badge" :class="conversation.source">
                  {{ getSourceLabel(conversation.source) }}
                </span>
              </td>
              <td>
                <div class="count">{{ conversation.messages.length }}</div>
              </td>
              <td>{{ conversation.createdAt }}</td>
              <td>{{ conversation.updatedAt }}</td>
              <td class="actions">
                <button class="view-btn" @click="openDetail(conversation)">
                  查看详情
                </button>
                <button
                  class="delete-btn"
                  @click="deleteConversation(conversation.id)"
                >
                  删除记录
                </button>
              </td>
            </tr>
          </tbody>
        </table>
      </div>
    </div>

    <div v-if="showDetail" class="dialog-overlay" @click="closeDetail">
      <div class="dialog" @click.stop>
        <div class="dialog-header">
          <div>
            <h2>{{ activeConversation?.title }}</h2>
            <p class="dialog-subtitle">编号 {{ activeConversation?.id }}</p>
          </div>
          <button class="close-btn" @click="closeDetail">×</button>
        </div>
        <div class="dialog-body">
          <div class="meta-grid">
            <div class="meta-card">
              <span class="meta-label">创建时间</span>
              <span class="meta-value">{{
                activeConversation?.createdAt
              }}</span>
            </div>
            <div class="meta-card">
              <span class="meta-label">最近更新时间</span>
              <span class="meta-value">{{
                activeConversation?.updatedAt
              }}</span>
            </div>
            <div class="meta-card">
              <span class="meta-label">来源</span>
              <span
                class="meta-value source-badge"
                :class="activeConversation?.source"
              >
                {{ getSourceLabel(activeConversation?.source) }}
              </span>
            </div>
            <div class="meta-card">
              <span class="meta-label">消息数量</span>
              <span class="meta-value">{{ activeMessages.length }}</span>
            </div>
          </div>

          <div class="message-section">
            <div v-if="detailLoading" class="detail-state loading">
              正在加载对话详情...
            </div>
            <div v-else-if="detailError" class="detail-state error">
              {{ detailError }}
            </div>
            <div v-else-if="!activeMessages.length" class="detail-state empty">
              暂无消息内容
            </div>
            <div v-else class="message-timeline">
              <div
                v-for="(message, index) in activeMessages"
                :key="message.id"
                class="message-item"
                :class="message.role"
              >
                <div class="message-meta">
                  <span class="role-badge" :class="message.role">
                    {{ message.role === "user" ? "用户" : "助手" }}
                  </span>
                  <span class="message-index">第 {{ index + 1 }} 条</span>
                </div>
                <p class="message-content">{{ message.content }}</p>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<style lang="scss" scoped>
.history-container {
  height: 100%;
  display: flex;
  flex-direction: column;
  background: transparent;
}

.history-header {
  padding: 24px 32px;
  background: linear-gradient(
    135deg,
    rgba(49, 190, 255, 0.08) 0%,
    rgba(49, 190, 255, 0.03) 100%
  );
  backdrop-filter: blur(20px);
  border-bottom: 1px solid rgba(49, 190, 255, 0.2);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);
  display: flex;
  justify-content: space-between;
  gap: 24px;
  align-items: flex-end;

  h1 {
    font-size: 28px;
    font-weight: 600;
    color: #f6f9fe;
    font-family: "YouSheBiaoTiHei", sans-serif;
    text-shadow: 0 2px 8px rgba(49, 190, 255, 0.3);
    margin-bottom: 6px;
  }
}

.header-actions {
  display: flex;
  align-items: end;
  gap: 16px;
}

.search-box {
  position: relative;

  input {
    width: 320px;
    padding: 10px 44px 10px 16px;
    background: rgba(26, 31, 58, 0.6);
    border: 1px solid rgba(49, 190, 255, 0.3);
    border-radius: 8px;
    font-size: 14px;
    color: #f6f9fe;
    font-family: "Alibaba PuHuiTi", sans-serif;
    transition: all 0.3s ease;

    &::placeholder {
      color: rgba(246, 249, 254, 0.5);
    }

    &:focus {
      border-color: rgba(49, 190, 255, 0.6);
      outline: none;
      background: rgba(26, 31, 58, 0.8);
      box-shadow: 0 0 0 3px rgba(49, 190, 255, 0.15),
        0 4px 12px rgba(49, 190, 255, 0.2);
    }
  }

  .search-icon {
    position: absolute;
    right: 16px;
    top: 50%;
    transform: translateY(-50%);
    width: 18px;
    height: 18px;
    border-radius: 50%;
    border: 2px solid rgba(49, 190, 255, 0.6);
    opacity: 0.7;

    &::after {
      content: "";
      position: absolute;
      width: 8px;
      height: 2px;
      background: rgba(49, 190, 255, 0.6);
      transform: rotate(45deg);
      right: -6px;
      bottom: -2px;
      border-radius: 2px;
    }
  }
}

.filter-group {
  display: flex;
  gap: 12px;
  align-items: end;
}

.filter-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-family: "Alibaba PuHuiTi", sans-serif;
  color: rgba(246, 249, 254, 0.7);
  font-size: 12px;

  input,
  select {
    width: 160px;
    padding: 10px 12px;
    background: rgba(26, 31, 58, 0.6);
    border: 1px solid rgba(49, 190, 255, 0.3);
    border-radius: 8px;
    font-size: 14px;
    color: #f6f9fe;
    font-family: "Alibaba PuHuiTi", sans-serif;
    transition: all 0.3s ease;

    &:focus {
      border-color: rgba(49, 190, 255, 0.6);
      outline: none;
      background: rgba(26, 31, 58, 0.8);
      box-shadow: 0 0 0 3px rgba(49, 190, 255, 0.15),
        0 4px 12px rgba(49, 190, 255, 0.2);
    }
  }
}

.reset-btn {
  padding: 10px 18px;
  background: rgba(49, 190, 255, 0.08);
  border: 1px solid rgba(49, 190, 255, 0.3);
  border-radius: 8px;
  color: rgba(246, 249, 254, 0.85);
  font-size: 14px;
  font-family: "Alibaba PuHuiTi", sans-serif;
  cursor: pointer;
  transition: all 0.3s ease;

  &:hover {
    background: rgba(49, 190, 255, 0.15);
    border-color: rgba(49, 190, 255, 0.4);
    transform: translateY(-2px);
  }
}

.history-content {
  flex: 1;
  overflow: auto;
  padding: 8px 32px 32px;
}

.table-container {
  background: linear-gradient(
    135deg,
    rgba(49, 190, 255, 0.05) 0%,
    rgba(49, 190, 255, 0.02) 100%
  );
  backdrop-filter: blur(20px);
  border: 1px solid rgba(49, 190, 255, 0.15);
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
}

.history-table {
  width: 100%;
  border-collapse: collapse;

  thead {
    background: linear-gradient(
      135deg,
      rgba(49, 190, 255, 0.15) 0%,
      rgba(49, 190, 255, 0.08) 100%
    );

    th {
      padding: 16px 20px;
      text-align: left;
      font-size: 14px;
      font-weight: 600;
      color: rgba(49, 190, 255, 0.9);
      font-family: "Alibaba PuHuiTi", sans-serif;
      border-bottom: 1px solid rgba(49, 190, 255, 0.2);
      text-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
    }
  }

  tbody {
    tr {
      transition: all 0.3s ease;

      &:hover {
        background: rgba(49, 190, 255, 0.08);
        box-shadow: inset 0 0 20px rgba(49, 190, 255, 0.1);
      }

      td {
        padding: 16px 20px;
        font-size: 14px;
        color: rgba(246, 249, 254, 0.85);
        font-family: "Alibaba PuHuiTi", sans-serif;
        border-bottom: 1px solid rgba(49, 190, 255, 0.1);
        vertical-align: middle;
      }
    }
  }
}

.title {
  font-size: 15px;
  font-weight: 600;
  color: #f6f9fe;
  font-family: "Alibaba PuHuiTi", sans-serif;
}

.count {
  font-size: 16px;
  font-weight: 600;
  color: #31beff;
  font-family: "YouSheBiaoTiHei", sans-serif;
}

.source-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 4px 12px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 500;
  font-family: "Alibaba PuHuiTi", sans-serif;
  background: rgba(49, 190, 255, 0.15);
  border: 1px solid rgba(49, 190, 255, 0.3);
  color: #31beff;

  &.internal {
    background: rgba(16, 185, 129, 0.15);
    border-color: rgba(16, 185, 129, 0.3);
    color: #10b981;
  }

  &.external {
    background: rgba(249, 115, 22, 0.15);
    border-color: rgba(249, 115, 22, 0.3);
    color: #f97316;
  }
}

.actions-col {
  width: 280px;
}

.view-btn,
.delete-btn {
  padding: 6px 16px;
  border: none;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 500;
  font-family: "Alibaba PuHuiTi", sans-serif;
  cursor: pointer;
  transition: all 0.3s ease;
}

.view-btn {
  background: linear-gradient(
    135deg,
    rgba(49, 190, 255, 0.2) 0%,
    rgba(49, 190, 255, 0.1) 100%
  );
  border: 1px solid rgba(49, 190, 255, 0.3);
  color: #31beff;
  margin-right: 10px;

  &:hover {
    background: linear-gradient(
      135deg,
      rgba(49, 190, 255, 0.3) 0%,
      rgba(49, 190, 255, 0.2) 100%
    );
    border-color: rgba(49, 190, 255, 0.5);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(49, 190, 255, 0.3);
  }
}

.actions .delete-btn {
  background: linear-gradient(
    135deg,
    rgba(220, 38, 38, 0.2) 0%,
    rgba(220, 38, 38, 0.1) 100%
  );
  border: 1px solid rgba(220, 38, 38, 0.3);
  color: #ef4444;

  &:hover {
    background: linear-gradient(
      135deg,
      rgba(220, 38, 38, 0.3) 0%,
      rgba(220, 38, 38, 0.2) 100%
    );
    border-color: rgba(220, 38, 38, 0.5);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(220, 38, 38, 0.3);
  }
}

.empty-state {
  padding: 60px 20px;
  text-align: center;
  color: rgba(246, 249, 254, 0.6);
  font-family: "Alibaba PuHuiTi", sans-serif;

  h3 {
    font-size: 20px;
    margin-bottom: 12px;
    font-family: "YouSheBiaoTiHei", sans-serif;
    color: #f6f9fe;
  }

  p {
    font-size: 14px;
  }
}

.dialog-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.72);
  backdrop-filter: blur(10px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  animation: fadeIn 0.3s ease;
}

.dialog {
  background: linear-gradient(
    135deg,
    rgba(26, 31, 58, 0.96) 0%,
    rgba(10, 14, 39, 0.96) 100%
  );
  backdrop-filter: blur(20px);
  border: 1px solid rgba(49, 190, 255, 0.3);
  border-radius: 12px;
  width: min(760px, 90%);
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.5), 0 0 20px rgba(49, 190, 255, 0.2);
  animation: slideUp 0.3s ease;
}

.dialog-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 20px 24px;
  border-bottom: 1px solid rgba(49, 190, 255, 0.2);
  background: linear-gradient(
    135deg,
    rgba(49, 190, 255, 0.08) 0%,
    rgba(49, 190, 255, 0.03) 100%
  );

  h2 {
    font-size: 20px;
    font-weight: 600;
    color: #f6f9fe;
    font-family: "YouSheBiaoTiHei", sans-serif;
    text-shadow: 0 2px 8px rgba(49, 190, 255, 0.3);
  }

  .dialog-subtitle {
    margin-top: 4px;
    font-size: 13px;
    color: rgba(246, 249, 254, 0.6);
    font-family: "Alibaba PuHuiTi", sans-serif;
  }
  .close-btn {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: 1px solid transparent;
    color: rgba(246, 249, 254, 0.6);
    font-size: 28px;
    cursor: pointer;
    border-radius: 6px;
    transition: all 0.3s ease;

    &:hover {
      background: rgba(49, 190, 255, 0.1);
      border-color: rgba(49, 190, 255, 0.3);
      color: #31beff;
      transform: rotate(90deg);
    }
  }
}

.dialog-body {
  padding: 24px;
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.meta-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 16px;
}

.meta-card {
  background: rgba(26, 31, 58, 0.7);
  border: 1px solid rgba(49, 190, 255, 0.2);
  border-radius: 10px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;

  .meta-label {
    font-size: 12px;
    color: rgba(246, 249, 254, 0.6);
    font-family: "Alibaba PuHuiTi", sans-serif;
  }

  .meta-value {
    font-size: 15px;
    color: #f6f9fe;
    font-family: "Alibaba PuHuiTi", sans-serif;
  }
}

.message-timeline {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.message-item {
  padding: 16px;
  border-radius: 10px;
  border: 1px solid rgba(49, 190, 255, 0.15);
  background: rgba(26, 31, 58, 0.6);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
  display: flex;
  flex-direction: column;
  gap: 10px;
  position: relative;

  &.assistant {
    border-color: rgba(49, 190, 255, 0.3);
  }

  &.user {
    border-color: rgba(99, 102, 241, 0.3);
  }
}

.message-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-family: "Alibaba PuHuiTi", sans-serif;
}

.role-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 54px;
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 500;
  background: rgba(49, 190, 255, 0.15);
  border: 1px solid rgba(49, 190, 255, 0.3);
  color: #31beff;

  &.user {
    background: rgba(99, 102, 241, 0.18);
    border-color: rgba(99, 102, 241, 0.3);
    color: #a5b4fc;
  }
}

.message-index {
  font-size: 12px;
  color: rgba(246, 249, 254, 0.6);
}

.message-content {
  font-size: 14px;
  line-height: 1.7;
  color: rgba(246, 249, 254, 0.85);
  font-family: "Alibaba PuHuiTi", sans-serif;
}

.dialog-footer {
  display: flex;
  justify-content: flex-end;
  gap: 12px;
  padding: 20px 24px;
  border-top: 1px solid rgba(49, 190, 255, 0.2);
  background: linear-gradient(
    135deg,
    rgba(49, 190, 255, 0.03) 0%,
    rgba(49, 190, 255, 0.01) 100%
  );
}

.dialog-footer .delete-btn {
  background: linear-gradient(
    135deg,
    rgba(220, 38, 38, 0.25) 0%,
    rgba(220, 38, 38, 0.15) 100%
  );
  border: 1px solid rgba(220, 38, 38, 0.4);
  color: #ef4444;

  &:hover {
    background: linear-gradient(
      135deg,
      rgba(220, 38, 38, 0.35) 0%,
      rgba(220, 38, 38, 0.25) 100%
    );
    border-color: rgba(220, 38, 38, 0.6);
    transform: translateY(-2px);
  }
}

.dialog-footer .secondary {
  background: rgba(49, 190, 255, 0.08);
  border: 1px solid rgba(49, 190, 255, 0.2);
  color: rgba(246, 249, 254, 0.7);

  &:hover {
    background: rgba(49, 190, 255, 0.15);
    border-color: rgba(49, 190, 255, 0.3);
    color: #f6f9fe;
    transform: translateY(-2px);
  }
}

@keyframes fadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

@keyframes slideUp {
  from {
    transform: translateY(30px);
    opacity: 0;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

@media (max-width: 1280px) {
  .history-header {
    flex-direction: column;
    align-items: flex-start;
  }

  .header-actions {
    width: 100%;
    flex-wrap: wrap;
  }

  .filter-group {
    flex-wrap: wrap;
  }

  .filter-field input,
  .filter-field select {
    width: 200px;
  }

  .actions {
    flex-direction: column;
    align-items: flex-start;
  }

  .actions-col {
    width: 140px;
  }
}

@media (max-width: 768px) {
  .search-box input {
    width: 100%;
  }

  .filter-field input,
  .filter-field select {
    width: 100%;
  }
}
</style>
